<?php

$installer = $this;
$installer->startSetup();

$productTableName = Mage::getSingleton('core/resource')->getTableName('catalog/product');
$storeTableName = Mage::getSingleton('core/resource')->getTableName('core/store');

$installer->run("
DROP TABLE IF EXISTS {$this->getTable('zhishidi_question/question')};
CREATE TABLE {$this->getTable('zhishidi_question/question')} (
  `question_id` int(11) unsigned NOT NULL auto_increment,
  `store_id` smallint(5) unsigned NOT NULL default '0',
  `product_id` int unsigned not null,
  `name` varchar(255) NOT NULL default '',
  `email` varchar(255) NOT NULL default '',
  `question` text NOT NULL default '',
  `answer` text NOT NULL default '',
  `status` enum('public','hidden') default 'public',
  `ip` varchar(255) NOT NULL default '', 
  `created_on` datetime,
  `answered_on` datetime,
  PRIMARY KEY (`question_id`),
  CONSTRAINT FOREIGN KEY (`product_id`) REFERENCES {$productTableName} (`entity_id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT FOREIGN KEY (`store_id`) REFERENCES {$storeTableName} (`store_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

");

$installer->endSetup();
?>
